<?php  
	session_start();
include_once '../pushing.php';

if ($pushTime == true) {
	if ($_SESSION['UserId'] != 3)
		header('Location: push.php');
}
	
	if(!isset($_SESSION['UserId']))
	{
		header('Location: login.php');
   		die();
	}
	
	require '../Functions/SecureFunctions.php';
	
	if(isset($_REQUEST['Email']))
	{
		if(!$ValidationErrors = checkEmail($_REQUEST['Email'], getUserID()))
		{
			if(!$ValidationErrors = checkPassword($_REQUEST['CurrPassword']))
			{
				if(!$ValidationErrors = checktwoPasswords($_REQUEST['Password1'], $_REQUEST['Password2']))
				{
					changePassword($_REQUEST['Password2'], getUserID());
					
					//alert user that password has been changed
					echo '<script language="javascript" type="text/javascript">
					alert("Password Successfully Changed");
					redirect();
					function redirect(){
						window.location.href = "home.php";
					}
					</script>';	
				}
			}
		}
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Change Password</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

	<?php if (count($ValidationErrors) > 0 ) { ?> 
		$("#<?php echo $ValidationErrors[0]?>").css('color', 'red');
		$("#<?php echo $ValidationErrors[1]?>").css('border', '1px solid red');
	<?php } else {?>
		document.getElementById("Email").focus();

	<?php }?>
});
</script>
<link rel="stylesheet" type="text/css" href="../Styler.css"/>	
</head>

<body>
	 <div id="header"></div>

<div id="mainMenu" style="height: 65px; width: 100px;">
    	<ul style="list-style: none outside none;">
	        <li>
	       	 	<a href="home.php">Home</a>
	        </li> 
	         
	        <li>
	       	 	<a href="logout.php">Logout</a>
	        </li>
	        
        </ul>
</div>
   
	<?php if(isset($ValidationErrors)) {?>
	    <div class="noQueryResults" style="top: 140px; left: 350px;">
	    	<img src="../Images/error.png" style="float:left; margin: 5px 5px 5px 15px;"></img>
	    	<p style="font-weight: bold; line-height: 1; margin: 5px 5px 5px 55px;">Error</p>
			<p style="line-height: 1; margin: 5px 5px 5px 55px;"><?php echo $ValidationErrors[2];?></p>
	    </div>
    <?php } ?>
   
    <div id="login">
   	 	<div>
			Change Password
		</div>
		<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
	       <div>
	            <label for="Email" id="changePassEmail">Enter Email:</label>
	            <input type="text" name="Email" id="Email" <?php if (isset($_REQUEST['Email'])) { ?> value="<?php echo $_REQUEST['Email'];?>" <?php }?>/>
	       </div>
	        <div> 
	            <label for="Password" id="changePassPass">Current Password:</label>
	            <input type="password" name="CurrPassword" id="CurrPassword" />
	        </div>
	        <div>
	            <label for="Password" id="changePassNew">New Password:</label>
	            <input type="password" name="Password1" id="Password1" />
	        </div>
	         <div>
	            <label for="Password" id="changePassReNew">Re-enter Password:</label>
	            <input type="password" name="Password2" id="Password2" />
	        </div>
	        <input type="submit" value="Change" class="loginButton" />
	    </form>
    
    </div>
    
</body>
</html>